class BaiduImageryProvider {
	constructor(option) {
		var url = option.url;
		if (Cesium.defined(option.layer)) {
			switch (option.layer) {
				case "vec":
					url = 'http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=' + (option.bigfont ? 'ph' : 'pl') + '&scaler=1&p=1';
					break;
				case "img_d":
					url = 'http://shangetu{s}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46';
					break;
				case "img_z":
					url = 'http://online{s}.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&styles=' + (option.bigfont ? 'sh' : 'sl') + '&v=020';
					break;
	
				case "custom":
					//Custom 各种自定义样式
					//可选值：dark,midnight,grayscale,hardedge,light,redalert,googlelite,grassgreen,pink,darkgreen,bluish
					option.customid = option.style || 'midnight';
					url = 'http://api{s}.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&scale=1&customid=' + option.customid;
					break;
	
				case "time":
					//实时路况
					var time = new Date().getTime();
					url = 'http://its.map.baidu.com:8002/traffic/TrafficTileService?x={x}&y={y}&level={z}&time=' + time + '&label=web2D&v=017';
					break;
			}
		}
		
		let height = 33746824; //百度地图
		let width = 33554054;
		
		this._url = url;
		this._tileWidth = 256;
		this._tileHeight = 256;
		this._maximumLevel = 18;
	
		var rectangleSouthwestInMeters = new Cesium.Cartesian2(-width, -height);
		var rectangleNortheastInMeters = new Cesium.Cartesian2(width, height);
		this._tilingScheme = new Cesium.WebMercatorTilingScheme({ rectangleSouthwestInMeters: rectangleSouthwestInMeters, rectangleNortheastInMeters: rectangleNortheastInMeters });
	
		this._credit = undefined;
		this._rectangle = this._tilingScheme.rectangle;
		this._ready = true;
	}
	get url(){
		 return this._url;
	}
	get token(){
		 return this._token;
	}
	get proxy(){
		 return this._proxy;
	}
	
	get tileWidth(){
		if (!this._ready) {
		    throw new DeveloperError('tileWidth must not be called before the imagery provider is ready.');
		}
		return this._tileWidth;
	}
	get tileHeight(){
		if (!this._ready) {
		    throw new DeveloperError('tileHeight must not be called before the imagery provider is ready.');
		}
		return this._tileHeight;
	}
	get maximumLevel(){
		if (!this._ready) {
			throw new DeveloperError('maximumLevel must not be called before the imagery provider is ready.');
		}
		return this._maximumLevel;
	}
	
	get minimumLevel(){
		if (!this._ready) {
		    throw new DeveloperError('minimumLevel must not be called before the imagery provider is ready.');
		}
		return 0;
	}
	
	get tilingScheme(){
		if (!this._ready) {
		    throw new DeveloperError('tilingScheme must not be called before the imagery provider is ready.');
		}
		return this._tilingScheme;
	}
	get rectangle(){
		if (!this._ready) {
		    throw new DeveloperError('rectangle must not be called before the imagery provider is ready.');
		}
		return this._rectangle;
	}
	get tileDiscardPolicy(){
		if (!this._ready) {
		    throw new DeveloperError('tileDiscardPolicy must not be called before the imagery provider is ready.');
		}
		return this._tileDiscardPolicy;
	}
	get errorEvent(){
		 return this._errorEvent;
	}
	get ready(){
		return this._ready;
	}	
	get readyPromise(){
		 return this._readyPromise.promise;
	}
	get credit(){
		 return this._credit;
	}
	get usingPrecachedTiles(){
		 return this._useTiles;
	}
	get hasAlphaChannel(){
		return true;
	}
	get layers(){
		return this._layers;
	}
	getTileCredits(x, y, level){
		return undefined;
	}
	requestImage(x, y, level) {
	    if (!this._ready) {
	        throw new DeveloperError('requestImage must not be called before the imagery provider is ready.');
	    }
	    var tileW = this._tilingScheme.getNumberOfXTilesAtLevel(level);
	    var tileH = this._tilingScheme.getNumberOfYTilesAtLevel(level);
	
	    var url = this._url.replace('{x}', x - tileW / 2).replace('{y}', tileH / 2 - y - 1).replace('{z}', level).replace('{s}', "0");
	    return Cesium.ImageryProvider.loadImage(this, url);
	};
}
export {BaiduImageryProvider}